package br.com.beyondclick.view;

import java.util.Date;

import javax.ejb.EJB;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.log4j.Logger;

import br.com.beyondclick.model.repository.CompraRepository;

/**
 * @jsp.tag name="listarCompra" body-content="empty"
 */
public class ListaCompraTag extends TagSupport {
	private static final long serialVersionUID = 1L;

	private final static Logger logger = Logger.getLogger(ListaCompraTag.class);

	private Date inicio;
	private Date fim;

	@EJB(beanName="CompraRepositoryBeanRemote")
	private CompraRepository compraRepository;
	
	@Override
	public int doStartTag() throws JspException {
		try{
			HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
			request.setAttribute("compras", compraRepository.find(inicio, fim));
		}catch(Exception e){
			logger.warn("Erro ao recuperar a lista de compras.", e);
		}

		return SKIP_BODY;
	}
	
	
	/** 
	 * @jsp.attribute rtexprvalue="true" required="false" type = "Date"
     * @param inicio - data de inicio.
     */
	public void setInicio(Date inicio) {
		this.inicio = inicio;
	}
	
	/** 
	 * @jsp.attribute rtexprvalue="true" required="false" type = "Date"
	 * @param fim - data de fim.
	 */
	public void setFim(Date fim) {
		this.fim = fim;
	}	
}
